package com.hzgj.bcl.soa.cicada.lb;

import com.hzgj.bcl.soa.cicada.sender.Sender;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * Created by warning5 on 2017/3/13.
 */
public abstract class AbstractRule implements Rule {

    protected Logger logger = LoggerFactory.getLogger(getClass());

    protected LoadBalancer lb;

    @Override
    public LoadBalancer getLoadBalancer() {
        return lb;
    }

    @Override
    public void setLoadBalancer(LoadBalancer lb) {
        this.lb = lb;
    }

    @Override
    public Sender choose(Object key) {
        if (lb == null) {
            logger.warn("no load balancer");
            return null;
        }
        return choose(lb, key);
    }

    abstract Sender choose(LoadBalancer lb, Object key);
}
